#pragma config(Hubs,  S1, HTMotor,  HTMotor,  none,     none)
#pragma config(Hubs,  S2, HTMotor,  HTMotor,  none,     none)
#pragma config(Sensor, S1,     ,               sensorI2CMuxController)
#pragma config(Sensor, S2,     ,               sensorI2CMuxController)
#pragma config(Sensor, S3,     seekerL,        sensorHiTechnicIRSeeker1200)
#pragma config(Sensor, S4,     seekerR,        sensorHiTechnicIRSeeker1200)
#pragma config(Motor,  mtr_S1_C1_1,     aux1,          tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S1_C1_2,     aux2,          tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_1,     fl,            tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S1_C2_2,     fr,            tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S2_C1_1,     br,            tmotorTetrix, PIDControl, reversed, encoder)
#pragma config(Motor,  mtr_S2_C1_2,     bl,            tmotorTetrix, PIDControl, encoder)
#pragma config(Motor,  mtr_S2_C2_1,     ramp1,         tmotorTetrix, openLoop)
#pragma config(Motor,  mtr_S2_C2_2,     ramp2,         tmotorTetrix, openLoop, reversed)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#include "JoystickDriver.c"

int Xcor;

void hold()
{
	motor[br] = 0;
	motor[bl] = 0;
	motor[fr] = 0;
	motor[fl] = 0;
	wait1Msec(1200);
}

void rightSpeed(int power)
{
	motor[fr]=power;
	motor[br]=power;
	return;
}
void leftSpeed(int power)
{
	motor[fl]=power;
	motor[bl]=power;
	return;
}

void initalizeEncoders()
{
	nMotorEncoder[bl] = 0;
	nMotorEncoder[br] = 0;
	nMotorEncoder[fl] = 0;
	nMotorEncoder[fr] = 0;
	return;
}

task main()
{
	waitForStart();

  wait1Msec(6000);

	initalizeEncoders();

	nMotorEncoderTarget[bl] = 3050;       //forward
	nMotorEncoderTarget[br] = -3050;
	nMotorEncoderTarget[fl] = 3050;
	nMotorEncoderTarget[fr] = -3050;


	leftSpeed(50);
	rightSpeed(50);

	while(nMotorRunState[bl] != runStateIdle || nMotorRunState[br] != runStateIdle || nMotorRunState[fl] != runStateIdle || nMotorRunState[fr] != runStateIdle)
	{

	}

	hold();

	initalizeEncoders();



	nMotorEncoderTarget[bl] = 1150;    //turn
	nMotorEncoderTarget[br] = 1150;
	nMotorEncoderTarget[fl] = 1150;
	nMotorEncoderTarget[fr] = 1150;

	leftSpeed(50);
	rightSpeed(-50);

	while(nMotorRunState[bl] != runStateIdle || nMotorRunState[br] != runStateIdle || nMotorRunState[fl] != runStateIdle || nMotorRunState[fr] != runStateIdle)
	{

	}

		initalizeEncoders();

	nMotorEncoderTarget[bl] = 2050;       //forward
	nMotorEncoderTarget[br] = -2050;
	nMotorEncoderTarget[fl] = 2050;
	nMotorEncoderTarget[fr] = -2050;


	leftSpeed(50);
	rightSpeed(50);

	while(nMotorRunState[bl] != runStateIdle || nMotorRunState[br] != runStateIdle || nMotorRunState[fl] != runStateIdle || nMotorRunState[fr] != runStateIdle)
	{

	}

		initalizeEncoders();


	nMotorEncoderTarget[bl] = -2151;    //turn
	nMotorEncoderTarget[br] = -2151;
	nMotorEncoderTarget[fl] = -2151;
	nMotorEncoderTarget[fr] = -2151;

	leftSpeed(-50);
	rightSpeed(50);

	while(nMotorRunState[bl] != runStateIdle || nMotorRunState[br] != runStateIdle || nMotorRunState[fl] != runStateIdle || nMotorRunState[fr] != runStateIdle)
	{

	}


	hold();

  leftSpeed(0);
	rightSpeed(0);
	motor[aux1] = 50;
	motor[aux2] = 50;
  wait1Msec(1300);

	motor[aux1] = 0;
	motor[aux2] = 0;
	wait1Msec(300);


	hold();

	initalizeEncoders();

	nMotorEncoderTarget[bl] = 4300;
	nMotorEncoderTarget[br] = -4300;
	nMotorEncoderTarget[fl] = 4300;
	nMotorEncoderTarget[fr] = -4300;


	leftSpeed(50);
	rightSpeed(50);

	while(nMotorRunState[bl] != runStateIdle || nMotorRunState[br] != runStateIdle || nMotorRunState[fl] != runStateIdle || nMotorRunState[fr] != runStateIdle)
	{

	}

	hold();

	motor[aux1] = -50;
	motor[aux2] = -50;
	wait1Msec(300);

	motor[aux1] = 0;
	motor[aux2] = 0;
	wait1Msec(300);

	hold();

	nMotorEncoderTarget[bl] = -1440;
	nMotorEncoderTarget[br] = 1440;
	nMotorEncoderTarget[fl] = -1440;
	nMotorEncoderTarget[fr] = 1440;


	leftSpeed(-50);
	rightSpeed(-50);

	while(nMotorRunState[bl] != runStateIdle || nMotorRunState[br] != runStateIdle || nMotorRunState[fl] != runStateIdle || nMotorRunState[fr] != runStateIdle)
	{

	}




}
